
import { ElLoading, ElMessage } from "element-plus";
import type { Api_Response_Dto } from "./type";

let instance: any = undefined;
/**
 * 打开全屏加载
 * @param msg 
 * @returns 
 */
export const openLoading = (msg?: string) => {
    instance = ElLoading.service({
        lock: true,
        text: msg || "请稍后...",
        background: 'rgba(0, 0, 0, 0.7)',
    });
}

/**
 * 关闭全屏加载
 */
export const closeLoading = () => {
    if (instance)
        instance.close();
}

/**
 * 消息提醒
 * @param result 
 */
export const showMessage = (result: Api_Response_Dto) => {
    if (result.code === 0) {
        ElMessage.success(result.message);
    } else {
        ElMessage.error(result.message);
    }
    return result.code === 0;
}